<?php

App::uses('Crud', 'Model');
App::uses('Theme', 'Model');

class EvaluationDetail extends Crud
{
    public $useTable = 'evaluations_details';

    /**
     * Al Agregar/eliminar/actualizar las constantes de los modelos implica ir
     * y actualizar los comentarios en los campos de la tabla asociada a este modelo.
     */
    const STATUS_ENABLED = 1;
    const STATUS_DISABLED = 0;

    public function getEnabledByEvaluation($evalId) {
        $filters = array(
            'fields' => array(
                't.theme as theme',
                'EvaluationDetail.qualification as cal',
                't.minimum_qualification as min_cal'
            ),
            'joins' => array(
                array(
                    'table' => 'themes',
                    'alias' => 't',
                    'type' => 'INNER',
                    'conditions' => array(
                        't.id = EvaluationDetail.theme_id',
                        't.status' => Theme::STATUS_ENABLED
                    )
                )
            ),
            'conditions' => array(
                'EvaluationDetail.evaluation_id' => $evalId,
                'EvaluationDetail.status' => self::STATUS_ENABLED,
            )
        );
        return $this->flatArray($this->find('all', $filters));
    }

    public function getRegsEnabledByEvaluation($evalId) {
        $filters = array(
            'conditions' => array(
                'EvaluationDetail.evaluation_id' => $evalId,
                'EvaluationDetail.status' => self::STATUS_ENABLED,
            )
        );
        return $this->flatArray($this->find('all', $filters));
    }
}
